wx.cloud.init({
  env:"pethub-database"
})
const db = wx.cloud.database().collection("article")
const app = getApp()
Page({
  data: {},
  id:"",
  collected:false,
  response:{},
  onLoad: function (options) {
    if (!wx.getStorageSync("collection")){
      wx.setStorageSync("collection", [])
    }
    db.doc(options._id).get().then(res=>{
      this.response = res.data
      this.setData({data:res.data})
    })
  },
  collect:function(){
    if (!this.collected){
      this.collected = true
      var collection = wx.getStorageSync("collection")
      collection.push({
        id:this.response._id,
        cover:this.response.cover,
        description:this.response.description,
        title:this.response.title
      })
      wx.setStorageSync('collection', collection)
      wx.showToast({
        title: '收藏成功',
      })
      
    }
    else{
      wx.showToast({
        title: '已收藏好啦',
      })
    }
  },
  onShareAppMessage: function () {
    return{
      title:'萌宠成长记，记录萌宠点滴生活',
      path:'pages/article/article?id=${this.id}',
    }
  }
})